package com.fujitsu.cn.c;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.fujitsu.cn.dao.MailDao;
import com.fujitsu.cn.m.Mail;

/**
 * Servlet implementation class Send
 */
public class NewMail extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public NewMail() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	/* (non-Javadoc)
	 * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		String userName = request.getParameter("userName").trim();
		String password = request.getParameter("password").trim();
		String from = request.getParameter("from").trim(); 
		String to = request.getParameter("to").trim();
		String subject = request.getParameter("subject").trim();
		String body = request.getParameter("body").trim();
		
	    Mail mail = new Mail();
	    mail.setUserName(userName);
	    mail.setPassword(password);
	    mail.setMail_sender(from);
	    mail.setMail_receiver(to);
	    mail.setSubject(subject);
	    mail.setContent(body);
	    MailDao mailDao = new MailDao();
	    mailDao.newMail(mail);
	    
	}

}
